*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This file merges 2015 metropopulation area population to US MSAs that overlap with the Global Cities sample
* This ensures that we use the the same population when estimating (US MSAs) and predictung (Global Citie) employment weights

* Clean Global Cities names
	use "$data_125cities/PL GLOBAL CITY DATASET/PL_GLOBAL_CITY_DATA_METROPOP", clear
	gen Cityglobaldataset=strtrim(cty)
	save "$temp/PL_GLOBAL_CITY_DATA_METROPOP", replace

* Read relevant US MSA list	
	import excel "$data_USMETROS/Raw Numeric Data/METRO LIST/METRO_OVERLAP_GLOBAL_US.xlsx", clear first

* Merge population from Gobal Cities data set	
	merge 1:1  Cityglobaldataset using  "$temp/PL_GLOBAL_CITY_DATA_METROPOP"
	drop if _merge!=3 // for three MSAs, we have two seperate cities in the global data set 
					  // (Dallas-Fort Worth, Miami-Ft. Lauderdale, NYC-Newark); the population data is aggregated by these larger metro areas
	duplicates drop Metroidentifier, force
	rename Metroidentifier cbsafp
	keep cbsafp metropop_2015

* Save data
	save "$temp/metro_pop2015_Overlap_GlobalCity_USMETRO_DATA", replace 
	capture mkdir "$dataoutput/MSA-GlobalCities"
	save "$dataoutput/MSA-GlobalCities/metro_pop2015_Overlap_GlobalCity_USMETRO_DATA", replace 

* Script ends	